# -*- coding: UTF-8 -*-
# @create  : 2024/8/26 15:35
# @Author  : 天空之城
# @File    : run_test.py
import unittest
import os


def load_tests():
    test_loader = unittest.TestLoader()
    test_suite = unittest.TestSuite()

    # 遍历 tests 目录，加载所有测试用例
    for filename in os.listdir('test_address'):
        if filename.startswith('test_') and filename.endswith('.py'):
            module_name = f'test_address.{filename[:-3]}'  # 去掉 .py 后缀
            module = __import__(module_name, fromlist=[''])
            test_suite.addTests(test_loader.loadTestsFromModule(module))

    return test_suite


if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    all_tests = load_tests()
    runner.run(all_tests)
